//力扣33. 搜索旋转排序数组
//分情况:看target是在旋转后的 左边区间 还是 右边区间
class Solution {
    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length-1;
        if(nums[0]>target){
            while(right>=left){
                int mid = left + (right-left)/2;
                if(nums[mid] == target){
                    return mid;
                }else if(nums[mid] > target && nums[mid] < nums[0]){
                    right = mid-1;
                }else if(nums[mid] > target || nums[mid] < target){
                    left = mid+1;
                }
            }
        }else if(nums[0]<target){
            while(right>=left){
                int mid = left + (right-left)/2;
                if(nums[mid] == target){
                    return mid;
                }else if((nums[mid] < target && nums[mid] < nums[0])||(nums[mid] > target)){
                    right = mid -1;
                }else if(nums[mid] < target){
                    left = mid +1;
                }
            }
        }else{
            return 0;
        }
        return -1;
    }
}



//力扣153. 寻找旋转排序数组中的最小值
class Solution1 {
    public int findMin(int[] nums) {
        int flag = nums[0];
        int left = 0;
        int right = nums.length-1;
        while(right>=left){
            int mid = left + (right-left)/2;
            if(nums[mid] >= flag){
                left = mid + 1;
            }else{
                flag = nums[mid];
                right = mid - 1;
            }
        }
        return flag;
    }
}